package com.atguigu.b_test;

import java.util.Scanner;

/*
    案例3：从键盘读入学生成绩，找出最高分，并输出学生成绩等级。
        成绩>=最高分-10  等级为“A”
        成绩>=最高分-20  等级为“B”
        成绩>=最高分-30  等级为“C”
        其余等级为“D”
        提示：先读入学生人数，根据人数创建int数组，存放学生成绩
 */
public class Test10 {
    public static void main(String[] args) {
        //键盘录入
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学生人数 : ");
        int number = sc.nextInt();

        //根据学生人数创建容器-> 准备存储学生成绩
        int[] scores = new int[number];

        //请输入每一个学生的成绩
        for (int i = 0; i < scores.length; i++) {
            System.out.println("请您输入第 " + (i + 1) + " 个学生成绩 : ");
            int score = sc.nextInt();
            //把分数存入到指定位置
            scores[i] = score;
        }

        //求最高分 -> 数组元素求最值
        int max = scores[0];

        for (int i = 0; i < scores.length; i++) {
            if (scores[i] > max){
                max = scores[i];
            }
        }

        //对学生进行评级
        for (int i = 0; i < scores.length; i++) {
            int score = scores[i];
            if (score >= max - 10){
                System.out.println("Student " + (i + 1) + " , score is " + score + ", grade is A");
            } else if (score >= max - 20){
                System.out.println("Student " + (i + 1) + " , score is " + score + ", grade is B");
            } else if (score >= max - 30) {
                System.out.println("Student " + (i + 1) + " , score is " + score + ", grade is C");
            }else {
                System.out.println("Student " + (i + 1) + " , score is " + score + ", grade is D");
            }
        }
    }
}
